<template>
  <el-dialog
    ref="dislogRef"
    @close="dialogVisibleClose"
    :visible.sync="dialogVisible"
    lock-scroll
    width="50%"
  >
    <div slot="title" class="header_title">
      <span class="title_span">条码库</span>
    </div>
    <div class="content_div">
      <div class="info_table">
        <div class="div_table">
          <div class="table_content">
            <el-table
              v-loading="loading"
              :data="tableData"
              @row-click="onClickRow"
              @row-dblclick="ondbClickRow"
              :row-class-name="tableRowClassName"
              height="100%"
            >
              <el-table-column min-width="200" property="name" label="商品名称"></el-table-column>
              <el-table-column min-width="150" property="barcode" label="条形码"></el-table-column>
              <el-table-column min-width="100" property="specification" label="规格"></el-table-column>
              <el-table-column min-width="60" property="unit" label="单位"></el-table-column>
              <el-table-column min-width="60" property="originName" label="产地"></el-table-column>
            </el-table>
          </div>
        </div>
      </div>
      <div class="info_button">
        <el-button type="primary" @click="onSelectRow">选择</el-button>
        <el-button @click.stop="dialogVisible = false">取消</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import { mapGetters } from 'vuex'
import axios from 'axios'
export default {
  name: 'BasicInformation',
  props: {
    commodityName: String,
  },
  computed: {
    ...mapGetters(['name']),
  },
  data () {
    return {
      loading: true,
      selectRow: {}, //当前选择的数据
      tableData: [],
      dialogVisible: false, // 新增弹框
    }
  },
  methods: {
    tableRowClassName ({ row }) {
      if (row.id === this.selectRow.id) {
        return 'select_row'
      }
    },
    getData () {
      let url =
        ' http://7077.xgohe.cn:9500/sys/business/commoditybarcode/queryCommodityBarcodeList?companyId=000&&pageNo=2&&pageSize=20&&name=' +
        this.commodityName
      axios.get(url).then((res) => {
        this.tableData = res.data.data
        this.loading = false
      })
    },
    // 选中当前行
    onClickRow (row) {
      this.selectRow = row
    },
    ondbClickRow (row) {
      this.selectRow = row
      this.onSelectRow()
    },
    // 选中后传递给父组件
    onSelectRow () {
      this.loading = true
      this.tableData = []
      var objStr = JSON.stringify(this.selectRow)
      if (objStr == '{}') {
        this.$elMessage.warning('请选择一条信息')
      } else {
        this.$emit('onSelectCommodity', this.selectRow)
        this.dialogVisible = false
      }
    },
    dialogVisibleClose () {
      this.loading = true
      this.tableData = []
      this.dialogVisible = false
    },
  },
}
</script>

<style lang="scss" scoped>
::v-deep .el-dialog {
  width: 100%;
  margin-top: 20vh !important;
  .el-dialog__body {
    padding: 0;
  }
  .el-dialog__header {
    width: 100%;
    height: 0.937559rem;
    box-sizing: border-box;
    padding: 0 0.187512rem 0 0.281268rem;
    border-bottom: 1px solid #eeeeee;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .el-dialog__headerbtn {
      position: static;
      .el-icon-close {
        color: #999;
        font-size: 0.48753rem;
      }
    }
  }
  .header_title {
    width: 100%;
    display: flex;
    align-items: center;
    .title_span {
      white-space: nowrap;
      font-size: 0.300019rem;
      color: #666;
      font-weight: 600;
    }
  }
}
.content_div {
  width: 100%;
  height: 50vh;
  background: #fff;
  box-sizing: border-box;
  padding: 0.187512rem 0.281268rem;
  .info_table {
    width: 100%;
    height: calc(100% - 0.937559rem);
    display: flex;
    .div_table {
      width: 100%;
      height: 100%;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      .table_content {
        height: 100%;
        ::v-deep .el-table {
          border: 1px solid #e3e3e3;
          box-sizing: border-box;
          th,
          td {
            padding: 0;
            color: #666;
            box-sizing: border-box;
            border-right: 1px solid #e3e3e3;
            .cell {
              height: 30px;
              display: flex;
              align-items: center;
              font-size: 12px;
            }
          }
          th {
            .cell {
              background: #ededed;
              justify-content: center;
            }
          }
          .el-table__body tr:hover > td {
            background: #e3f6ff;
          }
          .el-table__footer-wrapper {
            td {
              background: #f4f4f4;
              border: none;
            }
          }
          //滚动条的宽度
          ::-webkit-scrollbar {
            width: 10px;
            height: 10px;
            background-color: #e5e5e5;
          }
          //滚动条的滑块
          ::-webkit-scrollbar-thumb {
            background-color: #c9c9c9;
          }
        }
      }
      .total_record {
        width: 100%;
        height: 30px;
        box-sizing: border-box;
        padding: 0 0.281268rem;
        border: 1px solid #e3e3e3;
        border-top: none;
        background: #f4f4f4;
        display: flex;
        p {
          margin: 0;
          line-height: 30px;
          padding-right: 0.281268rem;
          font-size: 12px;
          font-family: PingFang SC;
          font-weight: 500;
          color: #666666;
        }
      }
    }
  }
  .info_button {
    width: 100%;
    height: 0.750047rem;
    height: 0.937559rem;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    ::v-deep .el-button {
      width: 1.12507rem;
      height: 30px;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 0.093756rem;
    }
  }
}
::v-deep .select_row {
  background-color: #e3f6ff !important;
}
</style>